package com.felix.algorithms.planning;

import static java.lang.Math.max;
import static java.lang.Math.min;

/**
 * MinCostClimbingStairs
 *
 * @author xuejinhua
 * @date 2018/9/13 14:18
 */
public class MinCostClimbingStairs {

    /**
     * Q746
     *
     * @return
     */
    public static int solution(int[] cost) {
        if (cost.length == 0) {
            return 0;
        }
        if (cost.length == 1) {
            return cost[0];
        }
        int[] values = new int[2];
        values[0] = cost[0];
        values[1] = cost[1];
        for (int i = 2; i < cost.length; i++) {
            int temp = Math.min(values[0], values[1]) + cost[i];
            values[0] = values[1];
            values[1] = temp;
        }
        return Math.min(values[0], values[1]);
    }

    public static void main(String[] args) {
        int[] cost = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        System.out.println(solution(cost));
    }
}
